package com.hxkj.config;

import com.integral.mall.file.po.SpringContextHolder;
import com.integral.mall.file.storage.StorageFactory;
import com.integral.mall.file.storage.sftp.SFTPStorage;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 文件上传配置
 * created by kezhijie on 2018/8/30 10:46.
 * email to kezhijie@hxoss.com
 */
@Configuration
public class SftpConfig {
    /**
     * 存储工厂
     *
     * @return
     */
    @Bean("storageFactory")
    @ConfigurationProperties(prefix = "storage.sftp")
    public StorageFactory storageFactory() {
        return new StorageFactory();
    }


    @Bean("springContextHolder")
    public SpringContextHolder springContextHolder() {
        SpringContextHolder springContextHolder = new SpringContextHolder();
        return springContextHolder;
    }


    @Bean(value = "storage", initMethod = "init", destroyMethod = "destroy")
    public SFTPStorage sftpStorage(StorageFactory storageFactory) throws Exception {
        SFTPStorage sftpStorage = (SFTPStorage) storageFactory.getStorage();
        return sftpStorage;
    }
}
